package com.linkage.jz.bankruptcy.activity.Project.ZQUser.DetailOper;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.linkage.jz.bankruptcy.BankruptcyApp;
import com.linkage.jz.bankruptcy.Consts;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.activity.Main.CreateAddrActivity;
import com.linkage.jz.bankruptcy.adapter.FullyGridLayoutManager;
import com.linkage.jz.bankruptcy.base.BaseCreateActivity;
import com.linkage.jz.bankruptcy.bean.ApplyChangerZQUserNameBean;
import com.linkage.jz.bankruptcy.bean.TaskAtta;
import com.linkage.jz.bankruptcy.bean.ZQUserDetailBaseInfo;
import com.linkage.jz.bankruptcy.event.RefreshEvent;
import com.linkage.jz.bankruptcy.net.BaseSubscriber;
import com.linkage.jz.bankruptcy.net.Network;
import com.linkage.jz.bankruptcy.net.ToastUtil;
import com.linkage.jz.bankruptcy.utils.SPUtils;
import com.linkage.jz.bankruptcy.utils.Utils;
import com.linkage.jz.bankruptcy.widget.ApplyBaseReplyDialog;
import com.linkage.jz.bankruptcy.widget.CommonPromptDialog;
import com.linkage.jz.bankruptcy.widget.PublicNoticeDialog;
import com.linkage.jz.bankruptcy.widget.ShapeLoadingDialog;
import com.linkage.seapeak.pojo.UploadImage;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;


/**
 * 变更法定代表人姓名
 */
public class ApplyChangerLegalRepActivity extends BaseCreateActivity implements OnClickListener {

    private int REQUEST_CODE_ADDRESS = 10001;
    PublicNoticeDialog noticeDialog;
    //    private EditText et_Name,et_socialcode,et_fddbz,et_openbank,et_countname,et_fddbrzfzm,et_chanegenote;
    private TextView et_legalrap_name, et_legalrap_phone, et_legalrap_other_phone, et_legalrap_email, et_legalrap_id, et_chanegenote,et_applynote,et_apply_ret;

    private TextView sendAddress;
//    private CheckBox ck_online1,ck_online2,ck_downline1,ck_downline2,ck_line2;

    private RecyclerView mImgRecyclerView1, mImgRecyclerView2;

    private List<UploadImage> mImgList1 = new ArrayList<>();
    private GridImagesAdapter mImgAdapter1;
    private List<UploadImage> mImgList2 = new ArrayList<>();
    private GridImagesAdapter mImgAdapter2;

    protected ShapeLoadingDialog mShapeLoadingDialog;
    private static int mType; //0审核，1查看

    private TextView btn_commit;
    private static final String TAG = ApplyChangerLegalRepActivity.class.getSimpleName();

    private static Boolean mFlag;

    @Override
    public void setListener() {

    }

    @Override
    public void initTitle() {
    }

    @Override
    public void initView() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == REQUEST_CODE_ADDRESS) {
//                address = (AddressInfo) data.getSerializableExtra("address");
//                tvAddr.setText(address.getDetailString());
                sendAddress.setTag(data.getStringExtra("id"));
                sendAddress.setText(data.getStringExtra("desc"));
            }
        }
    }

    //    private static String mProID;
//    public static void start(Context context,MyProInfo info) {
//        Intent intent = new Intent(context, CreateProFlowActivity.class);
//        mInfo = info;
//        context.startActivity(intent);
//    }
    CommonPromptDialog mPromptDialog;
    private ApplyBaseReplyDialog dialog;

    private static ApplyChangerZQUserNameBean mInfo;

//    private static String mType;


    public static void start(Context context, ApplyChangerZQUserNameBean info, int type,boolean flag) {
        Intent intent = new Intent(context, ApplyChangerLegalRepActivity.class);
        mInfo = info;
        mType = type;
        mFlag = flag;
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_apply_changer_legalcrep);
        super.onCreate(savedInstanceState);
        titlebar_title = findViewById(R.id.top_title);
        if(mType == 0) {
            if(mFlag)
            {
                titlebar_title.setText("变更为法定代表人审核");
            }else {
                titlebar_title.setText("变更为新的法定代表人审核");
            }
        }else{
            if(mFlag) {
                titlebar_title.setText("变更为法定代表人");
            }else{
                titlebar_title.setText("变更为新的法定代表人");
            }
        }



        initViews();
        initData();


    }

    @Override
    public void onClick(View view) {


        switch (view.getId()) {


            case R.id.top_back:
                finishpage();
                break;
            default:
                break;
        }


    }

    private void initViews() {
        titlebar_back = findViewById(R.id.top_back);
        titlebar_menu_text = findViewById(R.id.top_mune1);
        titlebar_back.setOnClickListener(this);
        titlebar_menu_text.setText("发送");
        titlebar_menu_text.setVisibility(View.INVISIBLE);

        titlebar_menu_text.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                saveData();
            }
        });

        btn_commit = findViewById(R.id.btn_commit);
        if (mType == 0) {
            btn_commit.setVisibility(View.VISIBLE);
        } else {
            btn_commit.setVisibility(View.GONE);
        }

        btn_commit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                dialog = new ApplyBaseReplyDialog(ApplyChangerLegalRepActivity.this, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (v.getId() == R.id.btn_save) {
                            String msg = dialog.text_reason.getText().toString().trim();
                            String status = "1";
                            if (dialog.cb_nopass.isChecked()) {
                                status = "2";
                            }
                            String notifyTypes = "";
                            if (dialog.send_msg.isChecked() && dialog.send_phone.isChecked()) {
                                notifyTypes = "0,1";
                            } else if (dialog.send_msg.isChecked()) {
                                notifyTypes = "0";
                            } else {
                                notifyTypes = "1";
                            }


//                    addZQUser(name,phone);
                            applyPerson(status, msg, notifyTypes);
                            dialog.dismiss();
                        }
                        if (v.getId() == R.id.btn_chancel) {
                            dialog.dismiss();
                        }

                    }
                });
                dialog.show();
            }
        });


        et_legalrap_name = findViewById(R.id.et_legalrap_name);
        et_legalrap_phone = findViewById(R.id.et_legalrap_phone);
        et_legalrap_other_phone = findViewById(R.id.et_legalrap_other_phone);
        et_legalrap_email = findViewById(R.id.et_legalrap_email);
        et_legalrap_id = findViewById(R.id.et_legalrap_id);
        et_chanegenote = findViewById(R.id.et_chanegenote);
        sendAddress = findViewById(R.id.et_addr);

        if(mInfo.getChange()!=null)
        {
            et_legalrap_name.setText( Utils.tmpString(mInfo.getChange().getLegalRepresentativeName()));
            et_legalrap_phone.setText( Utils.tmpString(mInfo.getChange().getContact()));
            et_legalrap_other_phone.setText( Utils.tmpString(mInfo.getChange().getOtherContact()));
            et_legalrap_email.setText( Utils.tmpString(mInfo.getChange().getEmail()));
            et_legalrap_id.setText( Utils.tmpString(mInfo.getChange().getCardNumber()));
            et_chanegenote.setText( Utils.tmpString(mInfo.getChange().getChangeDetail()));
            et_applynote = findViewById(R.id.et_applynote);
            et_apply_ret = findViewById(R.id.et_apply_ret);

            String addr = "";
            if (mInfo.getChange().getAddressInfo() != null) {
                if (mInfo.getChange().getAddressInfo().getProvince() != null) {
                    addr = mInfo.getChange().getAddressInfo().getProvince();
                }

                if (mInfo.getChange().getAddressInfo().getCity() != null) {
                    addr += mInfo.getChange().getAddressInfo().getCity();
                }

                if (mInfo.getChange().getAddressInfo().getRegion() != null) {
                    addr += mInfo.getChange().getAddressInfo().getRegion();
                }

                if (mInfo.getChange().getAddressInfo().getAddress() != null) {
                    addr += mInfo.getChange().getAddressInfo().getAddress();
                }

            }
            sendAddress.setVisibility(View.GONE);
            sendAddress.setText( Utils.tmpString(addr));
        }else{
            if(mInfo.getCreditorInfo()!=null) {
                et_legalrap_name.setText( Utils.tmpString(mInfo.getCreditorInfo().getLegalRepresentativeName()));
                et_legalrap_phone.setText( Utils.tmpString(mInfo.getCreditorInfo().getContact()));
                et_legalrap_other_phone.setText( Utils.tmpString(mInfo.getCreditorInfo().getOtherContact()));
                et_legalrap_email.setText( Utils.tmpString(mInfo.getCreditorInfo().getEmail()));
                et_legalrap_id.setText( Utils.tmpString(mInfo.getCreditorInfo().getCardNumber()));
                et_chanegenote.setText( Utils.tmpString(mInfo.getCreditorInfo().getChangeDetail()));
                et_applynote = findViewById(R.id.et_applynote);
                et_apply_ret = findViewById(R.id.et_apply_ret);

                String addr = "";
                if (mInfo.getCreditorInfo().getAddressInfo() != null) {
                    if (mInfo.getCreditorInfo().getAddressInfo().getProvince() != null) {
                        addr = mInfo.getCreditorInfo().getAddressInfo().getProvince();
                    }

                    if (mInfo.getCreditorInfo().getAddressInfo().getCity() != null) {
                        addr += mInfo.getCreditorInfo().getAddressInfo().getCity();
                    }

                    if (mInfo.getCreditorInfo().getAddressInfo().getRegion() != null) {
                        addr += mInfo.getCreditorInfo().getAddressInfo().getRegion();
                    }

                    if (mInfo.getCreditorInfo().getAddressInfo().getAddress() != null) {
                        addr += mInfo.getCreditorInfo().getAddressInfo().getAddress();
                    }

                }
                sendAddress.setVisibility(View.GONE);
                sendAddress.setText(addr);
            }
        }
//        sendAddress.setText(mInfo.getChange().getLegalRepresentativeName());


//        sendAddress.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent(ApplyChangerLegalRepActivity.this, CreateAddrActivity.class);
//                intent.putExtra(CreateAddrActivity.KEY_FROM, CreateAddrActivity.FROM_FLOW);
//                startActivityForResult(intent, REQUEST_CODE_ADDRESS);
//            }
//        });
        // 营业执照提供方式
//        ((RadioGroup) findViewById(R.id.rg_zqr_yyzz_type)).setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(RadioGroup radioGroup, int which) {
//                if (which == R.id.rg_zqr_yyzz_type_1) {
//                    provideBusinessLicense = TYPE_UPLOAD;
//                    findViewById(R.id.area_upload_yyzz).setVisibility(View.VISIBLE);
//                } else if (which == R.id.rg_zqr_yyzz_type_2) {
//                    provideBusinessLicense = TYPE_LOCAL;
//                    findViewById(R.id.area_upload_yyzz).setVisibility(View.GONE);
//                }
//            }
//        });
//
//        // 法人身份证明
//        ((RadioGroup) findViewById(R.id.rg_zqr_frsfzm_type)).setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(RadioGroup radioGroup, int which) {
//                if (which == R.id.rg_zqr_frsfzm_type_1) {
//                    provideLegalRepresentative = TYPE_UPLOAD;
//                    findViewById(R.id.area_upload_frsfzm).setVisibility(View.VISIBLE);
//                } else if (which == R.id.rg_zqr_frsfzm_type_2) {
//                    provideLegalRepresentative = TYPE_LOCAL;
//                    findViewById(R.id.area_upload_frsfzm).setVisibility(View.GONE);
//                }
//            }
//        });

        mImgRecyclerView1 = findViewById(R.id.recycler1);
        FullyGridLayoutManager manager = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false);
        mImgRecyclerView1.setLayoutManager(manager);
        mImgAdapter1 = new GridImagesAdapter(this, TYPE_PREVIEW);
        mImgAdapter1.setList(mImgList1);
        mImgRecyclerView1.setAdapter(mImgAdapter1);
        mImgAdapter1.setEnable(false);


        mImgRecyclerView2 = findViewById(R.id.recycler2);
        FullyGridLayoutManager manager2 = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false);
        mImgRecyclerView2.setLayoutManager(manager2);
        mImgAdapter2 = new GridImagesAdapter(this, TYPE_PREVIEW);
        mImgAdapter2.setList(mImgList2);
        mImgRecyclerView2.setAdapter(mImgAdapter2);
        mImgAdapter2.setEnable(false);

        if(mInfo.getChange()!=null)
        {
            if (mInfo.getChange().getProvideCardChangeAttas() != null) {
                for (int i = 0; i < mInfo.getChange().getProvideCardChangeAttas().size(); i++) {
                    TaskAtta atta = mInfo.getChange().getProvideCardChangeAttas().get(i);
                    JSONObject obj = new JSONObject();
                    try {
                        obj.putOpt("filename", atta.getAttachmentName());
                        obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                        obj.putOpt("filesize", atta.getAttachmentSize());
                        obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                        mImgList1.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }
            if (mInfo.getChange().getProvideLegalRepresentativeChangeAttas() != null) {
                for (int i = 0; i < mInfo.getChange().getProvideLegalRepresentativeChangeAttas().size(); i++) {
                    TaskAtta atta = mInfo.getChange().getProvideLegalRepresentativeChangeAttas().get(i);
                    JSONObject obj = new JSONObject();
                    try {
                        obj.putOpt("filename", atta.getAttachmentName());
                        obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                        obj.putOpt("filesize", atta.getAttachmentSize());
                        obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                        mImgList2.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }

            if (mType == 1) {
                findViewById(R.id.noshow_2).setVisibility(View.VISIBLE);
                et_applynote.setText(mInfo.getChange().getAuditDetail());
                et_apply_ret.setText(mInfo.getChange().getAuditStatus().getText());
            }
        }else{
            if(mInfo.getCreditorInfo()!=null)
            {
                if (mInfo.getCreditorInfo().getProvideCardChangeAttas() != null) {
                    for (int i = 0; i < mInfo.getCreditorInfo().getProvideCardChangeAttas().size(); i++) {
                        TaskAtta atta = mInfo.getCreditorInfo().getProvideCardChangeAttas().get(i);
                        JSONObject obj = new JSONObject();
                        try {
                            obj.putOpt("filename", atta.getAttachmentName());
                            obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                            obj.putOpt("filesize", atta.getAttachmentSize());
                            obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                            mImgList1.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
                if (mInfo.getCreditorInfo().getProvideLegalRepresentativeChangeAttas() != null) {
                    for (int i = 0; i < mInfo.getCreditorInfo().getProvideLegalRepresentativeChangeAttas().size(); i++) {
                        TaskAtta atta = mInfo.getCreditorInfo().getProvideLegalRepresentativeChangeAttas().get(i);
                        JSONObject obj = new JSONObject();
                        try {
                            obj.putOpt("filename", atta.getAttachmentName());
                            obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                            obj.putOpt("filesize", atta.getAttachmentSize());
                            obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                            mImgList2.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }

                if (mType == 1) {
                    findViewById(R.id.noshow_2).setVisibility(View.VISIBLE);
                    et_applynote.setText( Utils.tmpString(mInfo.getCreditorInfo().getAuditDetail()));
                    et_apply_ret.setText( Utils.tmpString(mInfo.getCreditorInfo().getAuditStatus().getText()));
                }
            }
        }

//        ck_online1.set

    }

    @Override
    public void initData() {

    }

    private boolean showflag = true;


    public void finishpage() {
        noticeDialog = new PublicNoticeDialog(ApplyChangerLegalRepActivity.this, new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (v.getId() == R.id.btn_save_notice) {
                    ApplyChangerLegalRepActivity.super.finish();
                }
                noticeDialog.dismiss();
            }
        }, 1, "提示", "放弃编辑？",
                "否", "是");
        noticeDialog.show();
    }

    public void saveData() {


        et_legalrap_name = findViewById(R.id.et_legalrap_name);
        et_legalrap_phone = findViewById(R.id.et_legalrap_phone);
        et_legalrap_other_phone = findViewById(R.id.et_legalrap_other_phone);
        et_legalrap_email = findViewById(R.id.et_legalrap_email);
        et_legalrap_id = findViewById(R.id.et_legalrap_id);
        sendAddress = findViewById(R.id.et_addr);


        if (TextUtils.isEmpty(et_legalrap_name.getText().toString())) {
            showToast("法定代表人姓名不可为空");
            return;
        }

        if (TextUtils.isEmpty(et_legalrap_phone.getText().toString())) {
            showToast("法定代表人电话不可为空");
            return;
        }

        if (mImgList1.size() < 1) {
            ToastUtil.showShort("证明文件不能为空");
            return;
        }
        JSONArray fileArr = new JSONArray();
        for (int i = 0; i < mImgList1.size(); i++) {
            fileArr.put(mImgList1.get(i).parse2JSON());
        }
        String provideCardInt = "2";
        if (mImgList1 != null && mImgList1.size() > 0) {
            provideCardInt = "1";
        }

        JSONArray fileArr2 = new JSONArray();
        for (int i = 0; i < mImgList2.size(); i++) {
            fileArr2.put(mImgList2.get(i).parse2JSON());
        }
        String provideLegalRepresentativeInt = "2";
        if (mImgList2 != null && mImgList2.size() > 0) {
            provideLegalRepresentativeInt = "1";
        }


        mShapeLoadingDialog.setLoadingText("提交信息中...");
        mShapeLoadingDialog.setCanceledOnTouchOutside(false);
        mShapeLoadingDialog.show();
        Observable<JsonObject> observable;


        Map<String, String> parms = new HashMap<>();
        parms.put("userToken", getUserToken());
        parms.put("projectId", mInfo.getChange().getBankruptcyProjectId());
        parms.put("creditorId", mInfo.getChange().getId() + "");

        parms.put("cardFileJson", fileArr.toString());
        parms.put("cardNumber", et_legalrap_id.getText().toString());
        parms.put("changeDetail", et_chanegenote.getText().toString());
        parms.put("contact", et_legalrap_phone.getText().toString());
        parms.put("email", et_legalrap_email.getText().toString());
        parms.put("legalRepresentativeName", et_legalrap_name.getText().toString());
        parms.put("mailingAddress", sendAddress.getText().toString());
        parms.put("otherContact", et_legalrap_other_phone.getText().toString());
        parms.put("proveFileJson", fileArr.toString());
        parms.put("provideCardInt", provideCardInt);
        parms.put("provideLegalRepresentativeInt", provideLegalRepresentativeInt);


        parms.put("type", mType + "");


        Network.getAPIService()
                .legalRepresentativeOp(parms)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<JsonObject>() {
                    @Override
                    public void onNext(JsonObject json) {
                        mShapeLoadingDialog.dismiss();
                        int code = json.get("code").getAsInt();
                        if (code != 0) {
                            super.onNext(json);
                            return;
                        }
                        RefreshEvent event = new RefreshEvent();
                        event.setType(RefreshEvent.TYPE_TALK);
                        EventBus.getDefault().post(event);
                        ToastUtil.showShort("提交成功");
                        finish();
                    }

                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mShapeLoadingDialog.dismiss();
                        super.onError(e);
                    }
                });
    }






    /**
     * 保存信息
     */
    public void applyPerson(String status, String msg, String notifyTypes) {
        if (BankruptcyApp.tokeninfo == null || BankruptcyApp.tokeninfo.getToken() == null) {
            return;
        }

        OkHttpClient okHttpClient = new OkHttpClient();
//        HashMap<String, String> params = new HashMap<String, String>();
        Random random = new Random();
        String rom = random.nextLong() + "";
        String timestamp = System.currentTimeMillis() + "";
        String userToken = SPUtils.getInstance(Consts.SPNAME).getString("userToken", "");
        String userId = SPUtils.getInstance(Consts.SPNAME).getString("userId", "");

        String auditType = "7";
        if(mFlag)
        {
            auditType = "1";
        }
//        String no = zqUserDetailInfo.get(0).getId();
        RequestBody requestBody = new FormBody.Builder()
                .add("appid", "1000000001")
                .add("nonce", rom)
                .add("timestamp", timestamp)
                .add("token", BankruptcyApp.tokeninfo.getToken())
                .add("userToken", userToken)
//                .add("creditorId", creditorId)
                .add("auditState", status)
                .add("auditDesc", msg)
                .add("noticeTypes", notifyTypes)
                .add("projectId", mInfo.getChange().getBankruptcyProjectId())
                .add("changeId", mInfo.getChange().getId())
                .add("auditType", auditType)
                .build();

        String url = Consts.WEBURL_RIGHTSAUDIT;
        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();

        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
//                shapeLoadingDialog.dismiss();
//                Log.d(TAG, "onFailure: " + e.getMessage());
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        //更新UI
                        Toast.makeText(ApplyChangerLegalRepActivity.this, "保存失败", Toast.LENGTH_SHORT).show();

                    }

                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
//                Log.d(TAG, response.protocol() + " " +response.code() + " " + response.message());
                Headers headers = response.headers();
//

                String str = response.body().string();
                try {
                    final JSONObject object = new JSONObject(str);
                    if (object.optInt("code") == 0) {
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                //更新UI

                                com.linkage.seapeak.utils.ToastUtil.getInstance(ApplyChangerLegalRepActivity.this).showShortToast("审核成功");
                                finish();
//                                Toast.makeText(ApplyChangerZQUserNameActivity.this, "替吉奥成功", Toast.LENGTH_SHORT).show();

                            }

                        });
//                        finish();

                    } else {
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                //更新UI
                                Toast.makeText(ApplyChangerLegalRepActivity.this, "保存失败" + object.optString("msg"), Toast.LENGTH_SHORT).show();

                            }

                        });

                    }
                    str = "";
                } catch (Exception ex) {
                    ex.printStackTrace();
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            //更新UI
                            Toast.makeText(ApplyChangerLegalRepActivity.this, "保存失败", Toast.LENGTH_SHORT).show();

                        }

                    });
                }
            }
        });
    }



}

